package com.start_eternity.oasissafewalk.utils;

import org.springframework.stereotype.Service;

/**
 * author:ZhangT
 * Date:2024 / 03 / 31 / 16:29
 * Description:
 */
@Service
public class WechatTools {

    public  static String getOpenid(String code, String appid, String secret) {
        // 调用接口必要的参数
        StringBuilder data=new StringBuilder();
        // appid、secret定义在配置文件中，注入到项目里
        data.append("appid="+appid+"&");
        data.append("secret="+ secret+"&");
        data.append("js_code="+ code+"&");
        data.append("grant_type="+ "authorization_code");
        String response = HttpUtils.getRequest("https://api.weixin.qq.com/sns/jscode2session?" + data);

        return response;
    }
}
